<template>
  <div>
    <el-form :model="form" label-width="auto" style="max-width: 900px">
      <el-form-item label="用户名">
        <el-input v-model="form.UserName" />
      </el-form-item>
      <el-form-item label="地址">
        <el-cascader size="large" :options="pcaTextArr" v-model="addressArray">
        </el-cascader>
      </el-form-item>
      <el-form-item label="部门">
        <el-select
          v-model="form.DepartmentId"
          placeholder="请选择部门"
          style="width: 150px"
        >
          <el-option label="IT信息部" :value="1" />
          <el-option label="人力资源部" :value="2" />
          <el-option label="财务部" :value="3" />
          <el-option label="销售部" :value="4" />
          <el-option label="行政部" :value="5" />
        </el-select>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="form.UserSex">
          <el-radio :value="true">男</el-radio>
          <el-radio :value="false">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="详细地址">
        <el-input v-model="form.UserAddress" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="adduser()">添加</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import axios from "axios";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRouter } from "vue-router";
import {
  provinceAndCityData,
  pcTextArr,
  regionData,
  pcaTextArr,
  codeToText,
} from "element-china-area-data";
const router = useRouter();
const form = reactive({
  UserName: "",
  UserPwd: "123456",
  UserSex: true,
  Province: "",
  City: "",
  County: "",
  DepartmentId: "",
  UserAddress: "",
  Creator: "admin",
  Updateor: "",
  isDeleted: false,
});
const addressArray = ref([]);
const adduser = () => {
  if (form.UserName == "") {
    ElMessage.error("用户名不得为空");
    return;
  }
  form.Province = addressArray.value[0];
  form.City = addressArray.value[1];
  form.County = addressArray.value[2];
  console.log(form);
  axios.post("https://localhost:7070/api/Adduser/Adduser", form).then((res) => {
    if (res.data.code == 100) {
      ElMessage.success(res.data.data);
      router.push("/GetUser");
    } else {
      ElMessage.error(res.data.message);
    }
  });
};
</script>

<style scoped>
</style>